import { makeAutoObservable } from 'mobx'
import { http } from '@/service'
import { setToken, getToken, clearToken } from '@/utils'
class LoginStore {
  token = getToken() ?? ''
  constructor() {
    // 响应式
    makeAutoObservable(this)
  }
  login = async ({ mobile, code }) => {
    const res = await http.post('/authorizations', {
      mobile,
      code,
    })
    this.token = res.data.token
    setToken(this.token)
  }
  // 退出登录
  loginOut = () => {
    this.token = ''
    clearToken()
  }
}

export default LoginStore
